﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using MOJsdk;

namespace MoJMoviePanels
{
    public class Plugin : IPlugIn
    {
        public string PluginDeveloper
        { get { return "Davidblkx"; } }
        public string PluginVersion
        { get { return "1"; } }
        public string PluginName
        { get { return "MoJIPanelControls"; } }
        public string PluginWeb
        { get { return ""; } }
        public string PluginDescription
        { get { return "Add 2 IPanels to MoJ"; } }
        public void Dispose()
        {

        }
        public void Install()
        {

        }
        public void Unistall()
        {

        }

        #region InicializeMethods
        public void Inicialize()
        {
            INIToolButtons();
            INIMainMenu();
        }
        private void INIToolButtons()
        {
            MojToolButton btnBrowse = new MojToolButton("BP", UserVars.BrowseMoviesToolButton, "Show BrowseMovies Control", null);
            MojToolButton btnManage = new MojToolButton("MP", UserVars.ManageMoviesToolButton, "Show ManageMovies Control", null);

            LogicStatment NotBrowseMovie = new LogicStatment();
            NotBrowseMovie.Code = string.Format("MojStatusVarsEnum.DisplayPanel.Value().PanelIdentifier != \"{0}\"", UserVars.BrowseMoviesPanel);
            LogicStatment NotManageMovie = new LogicStatment();
            NotManageMovie.Code = string.Format("MojStatusVarsEnum.DisplayPanel.Value().PanelIdentifier != \"{0}\"", UserVars.ManageMoviesPanel);

            btnBrowse.AddLogicStatment(NotBrowseMovie);
            btnBrowse.Click += OnBrowseMoviesToolButtonClicked;
            btnManage.AddLogicStatment(NotManageMovie);
            btnManage.Click += OnManageMoviesToolButtonClicked;

            MojHost.GetHost.ToolButtonCollection.Add(btnBrowse);
            MojHost.GetHost.ToolButtonCollection.Add(btnManage);
        }
        private void INIMainMenu()
        {
            Button btnBrowse = new Button();
            btnBrowse.Content = "Browse Movies";
            btnBrowse.Click += OnBrowseMoviesToolButtonClicked;
            btnBrowse.ApplyStyle("");
            MojHost.GetHost.MainMenu.AddNewButton(btnBrowse, 0);

            Button btnManage = new Button();
            btnManage.Content = "Manage";
            btnManage.Click += OnManageMoviesToolButtonClicked;
            btnManage.ApplyStyle("");
            MojHost.GetHost.MainMenu.AddNewButton(btnManage, 1);
        }
        #endregion

        #region Events
        public void OnBrowseMoviesToolButtonClicked(object sender, RoutedEventArgs e)
        {
            MojHost.GetHost.SetMoviePanel(new BrowseMoviesPanel());
        }
        public void OnManageMoviesToolButtonClicked(object sender, RoutedEventArgs e)
        {
            MojHost.GetHost.SetMoviePanel(new ManageMoviesControl());
        }
        #endregion
    }

    public class BrowseMoviesPanel : IPanel
    {
        BrowseMoviesControl _ctrl;
        public BrowseMoviesPanel()
        {
            _ctrl = new BrowseMoviesControl();
        }

        public UserControl Control { get { return _ctrl; } }
        public string PanelIdentifier { get { return UserVars.BrowseMoviesPanel; } }
        public string PanelType { get { return MojIPanelStandardTypes.BrowseMovies; } }

        public void LoadMovies()
        {

        }

        public void Focus() { }
        public void SelectNext() { }
        public void SelectPrev() { }
        public void SelectIndex(int Index) { }

        public void SelectMovie(string MovieCode) { }
        public void SelectMovies(List<string> MovieCodes) { }

        public void SelectFile(int FileId) { }
        public void SelectFiles(List<int> FileIds) { }

        public int CollectionSize { get { return 0; } }
        public bool IsMultiSelect { get { return false; } }

        public string SelectedMovie { get { return "NULL"; } }
        public int SelectedFile { get { return -1; } }

        public List<string> SelectedMovies { get { return new List<string>(); } }
        public List<int> SelectedFiles { get { return new List<int>(); } }

        public void ApplyMovieFilter() { }
        public void ApplyMovieOrder() { }

        public void ApplyFileFilter() { }
        public void ApplyFileOrder() { }

        public event SelectedMovieChangedHandler OnSelectedMovieChanged;
        public event SelectedFileChangedHandler OnSelectedFileChanged;
        public event CallEventHandler OnLoadComplete;

        public bool Equals(IPanel Panel)
        {
            return this.PanelIdentifier == Panel.PanelIdentifier;
        }
    }
}
